package com.cskaoyan.market.service;

import com.cskaoyan.market.db.domain.MarketFootprint;
import com.cskaoyan.market.db.domain.MarketFootprintExample;
import com.cskaoyan.market.db.domain.MarketGoods;
import com.cskaoyan.market.db.domain.MarketGoodsExample;
import com.cskaoyan.market.db.mapper.MarketFootprintMapper;
import com.cskaoyan.market.db.mapper.MarketGoodsMapper;
import com.cskaoyan.market.vo.WxFootprintListVo;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: MYM
 * @Date: 2024/05/20/14:10
 * @Description:
 */
@Service
public class WxFootprintServiceImpl implements WxFootprintService {
    @Autowired
    MarketFootprintMapper marketFootprintMapper;
    @Autowired
    MarketGoodsMapper marketGoodsMapper;

    @Override
    public List<MarketFootprint> page(Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<MarketFootprint> footprintList = marketFootprintMapper.selectByExample(new MarketFootprintExample());
        return footprintList;
    }

    @Override
    public List<WxFootprintListVo> list(Integer page, Integer limit) {
        List<MarketFootprint> goodsList = page(page, limit);
        List<WxFootprintListVo> voList = new ArrayList<>();
        MarketGoodsExample example = new MarketGoodsExample();
        for (MarketFootprint footprint : goodsList) {
            example.createCriteria().andIdEqualTo(footprint.getGoodsId());
            List<MarketGoods> goods = marketGoodsMapper.selectByExample(example);
            if (goods.size() > 0) {
            voList.add(new WxFootprintListVo(goods.get(0).getBrief(),footprint.getAddTime(), footprint.getGoodsId(),
                    footprint.getId(), goods.get(0).getName(), goods.get(0).getPicUrl(), goods.get(0).getRetailPrice()));
            }
        }
        return voList;
    }
}
